package com.agentframework.examples.jinhua;

import com.agentframework.core.annotation.Environment;
import com.agentframework.core.environment.AbstractEnvironment;
import org.springframework.beans.factory.ObjectProvider;

import java.util.List;

/**
 * @author wangjun
 **/
@Environment(name = "jinhuaEnvironment", agents = {JinhuaDealerAgent.class, JinhuaPlayerAgent.class})
public class JinhuaEnvironment extends AbstractEnvironment {

    /**
     * 游戏轮数
     */
    private int round;

    /**
     * 参与玩家数量
     */
    private int playerCount;

    private final JinhuaTool jinhuaTool;

    private JinhuaGameState jinhuaGameState;

    private final ObjectProvider<JinhuaPlayerAgent> playerAgentProvider;

    public JinhuaEnvironment(ObjectProvider<JinhuaPlayerAgent> playerAgentProvider, JinhuaTool jinhuaTool) {
        this.playerAgentProvider = playerAgentProvider;
        this.jinhuaTool = jinhuaTool;

        addListeners(List.of(new JinhuaInit(), new JinhuaStarted()));
        addEndCondition(new JinhuaGameEndCondition());
    }

    public void initPlayers() {
        setRound(3);
        setPlayerCount(3);
        for (int i = 0; i < playerCount; i++) {
            JinhuaPlayerAgent player = playerAgentProvider.getObject();
            player.setAgentName("player-" + (i + 1));
            addAgent(player);
        }
    }

    public void setRound(int round) {
        this.round = round;
    }

    public int getRound() {
        return round;
    }

    public void setPlayerCount(int playerCount) {
        this.playerCount = playerCount;
    }

    public int getPlayerCount() {
        return playerCount;
    }

    public JinhuaTool getJinhuaTool() {
        return jinhuaTool;
    }

    public JinhuaGameState getJinhuaGameState() {
        return jinhuaGameState;
    }

    public void setJinhuaGameState(JinhuaGameState jinhuaGameState) {
        this.jinhuaGameState = jinhuaGameState;
    }

}
